package org.summerframework.component.security.spring.exception;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.summerframework.core.base.result.DefaultResultCode;
import org.summerframework.core.base.result.ResultCode;
import org.summerframework.web.exception.resolver.ExceptionResolveHandler;
import org.springframework.security.access.AccessDeniedException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 石超
 * @version v1.0.0
 */
public class AccessDeniedExceptionResolveHandler implements ExceptionResolveHandler {
    @Resource
    private ObjectMapper objectMapper;

    @Override
    public ResultCode resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        return DefaultResultCode.getInstance(DefaultResultCode.ERROR_REQUEST_NOT_ACCEPTABLE.getCode(), "权限不足");
    }

    @Override
    public boolean supper(Exception ex) {
        return ex instanceof AccessDeniedException;
    }
}
